package LambdaDemo;

public class TestDemo {

    /**
     * 省略写法
     * @param args
     */
    public static void main(String[] args) {
        MoreParameterNoReturn moreParameterNoReturn = ( a, b)->{
            System.out.println("无返回值多个参数，省略参数类型："+a+" "+b);
        };
        moreParameterNoReturn.test(20,30);
        OneParameterNoReturn oneParameterNoReturn = a ->{
            System.out.println("无参数一个返回值,小括号可以胜率："+ a);
        };
        oneParameterNoReturn.test(10);
        NoParameterNoReturn noParameterNoReturn = ()->System.out.println("无参数无返回值，方法体中只有一行代码");
        noParameterNoReturn.test();

        //方法体中只有一条语句，且是return语句
        NoParameterReturn noParameterReturn = ()-> 40;
        int ret = noParameterReturn.test();
        System.out.println(ret);
    }


    /**
     * 正常写法
     * @param args
     */
    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = () -> {
            System.out.println("无参数无返回值");
        };
        noParameterNoReturn.test();
        OneParameterNoReturn oneParameterNoReturn = (int a) -> {
            System.out.println("一个参数无返回值：" + a);
        };
        oneParameterNoReturn.test(10);
        MoreParameterNoReturn moreParameterNoReturn = (int a, int b) -> {
            System.out.println("多个参数无返回值：" + a + " " + b);
        };
        moreParameterNoReturn.test(20, 30);
        NoParameterReturn noParameterReturn = () -> {
            System.out.println("有返回值无参数！");
            return 40;
        };
        //接收函数的返回值
        int ret = noParameterReturn.test();
        System.out.println(ret);
        OneParameterReturn oneParameterReturn = (int a) -> {
            System.out.println("有返回值有一个参数！");
            return a;
        };
        ret = oneParameterReturn.test(50);
        System.out.println(ret);
        MoreParameterReturn moreParameterReturn = (int a,int b)->{
            System.out.println("有返回值多个参数！");
            return a+b;
        };
        ret = moreParameterReturn.test(60,70);
        System.out.println(ret);
    }
}